﻿<%@ Page Title="" Language="C#" MasterPageFile="~/SIPO.master" AutoEventWireup="false"
    CodeFile="recInvoiceAlllist.aspx.cs" Inherits="SIPO.Web.Lists.Administration.Catalog.recInvoicelist" %>

<asp:Content ID="ctnBody" ContentPlaceHolderID="body" runat="server">
    <link type="text/css" rel="stylesheet" href="<%= ResolveUrl("~/styles/ui.jqgrid.css") %>" />
    <script type="text/javascript" src="<%= ResolveUrl("~/scripts/i18n/grid.locale-id.js") %>"></script>
    <script type="text/javascript" src="<%= ResolveUrl("~/scripts/jquery.jqGrid.min.js") %>"></script>
    <script src="<%= ResolveUrl("~/scripts/helper.js") %>" type="text/javascript"></script>
    <div>
        <%--<button id="btnAdd" type="button" onclick="OpenForm('add');">
            Add</button>--%>
        <button id="btnDelete" type="button" onclick="OpenForm('delete');">
            Hapus</button>
        <button id="btnPrint" type="button" onclick="OpenForm('print');">
            Cetak</button>
    </div>
    <br />
    <br />
    <table id="table" class="scroll" cellpadding="0" cellspacing="0">
    </table>
    <div id="pager" class="scroll">
    </div>
    <br />
    <div id="dialog" title="Default dialog">
    </div>
    <script type="text/javascript">

        //        $("#btnAdd").button({ icons: { primary: "ui-icon-plus"} });
        $("#btnDelete").button({ icons: { primary: "ui-icon-trash"} });
        $("#btnPrint").button({ icons: { primary: "ui-icon-print"} });
    </script>
    <script type="text/javascript">

        var handlerUrl = '<%= ResolveUrl("~/AjaxHandler/Transaction/recInvoicehandler.ashx") %>';

        $('#table').jqGrid({
            url: handlerUrl + '?method=getdata',
            datatype: 'json',
            colNames: ['ID', 'No. Surat Setoran', 'Sub Sub Sektor', 'Nama Perusahaan', 'Jumlah (Rp)', 'Tgl. Surat Setoran', 'No. Pembayaran', 'Tgl. Pembayaran', 'Detail'],
            colModel: [
                    { name: 'InvoiceNo', hidden: true, index: 'recInvoice.InvoiceNo', width: 150 },
                    { name: 'InvoiceNo', index: 'recInvoice.InvoiceNo', width: 150 },
                    { name: 'recDebtorSector.recSubSubSector.SubSubSectorName', index: 'recInvoice.DebtorSectorID', width: 300 },
                    { name: 'recDebtorSector.recDebtor.DebtorName', index: 'recInvoice.DebtorSectorID', width: 300 },
                    { name: 'InvoiceValue', index: 'InvoiceValue', width: 150, formatter: 'number', align: 'right' },
                    { name: 'InvoiceDate', index: 'InvoiceDate', align: 'center', width: 150, formatter: 'date', formatoptions: { newformat: 'd M Y'} },
                    { name: 'PaymentNo', index: 'PaymentNo', width: 150 },
                    { name: 'PaymentDate', index: 'PaymentDate', align: 'center', width: 120, formatter: 'date', formatoptions: { newformat: 'd M Y'} },

                    { name: 'InvoiceNo', index: 'InvoiceNo', align: 'center', formatter: returnMyLink, width: 100 }

           	],
            rowNum: 10,
            id: 'InvoiceNo',
            multiselect: true,
            rowList: [5, 10, 15, 20],
            pager: '#pager',
            sortname: 'recInvoice.InvoiceNo',
            sortorder: "asc",
            viewrecords: true,
            jsonReader: { repeatitems: false },
            width: 1250,
            height: '100%',
            caption: 'Tagihan',
            ajaxGridOptions: { cache: false }
        });

        $("#table").jqGrid('navGrid', '#pager', { edit: false, add: false, del: false, searchtext: 'Search', refreshtext: 'Refresh' },
        {}, {}, {}, { closeOnEscape: true, multipleSearch: true, closeAfterSearch: true });


        function popupform(cellValue) {
            var formUrl = '<%= ResolveUrl("~/forms/transaction/recInvoiceInfoform.aspx") %>';
            $('#dialog').load(formUrl + '?id=' + cellValue + '&statusdata=view&menuid=' + '<%= base.MenuID %>').dialog({ autoOpen: false, modal: true, width: 825, title: 'Detail Tagihan' });
            $("#dialog").dialog('open');
        }

        function returnMyLink(cellValue, options, rowdata) {
            var InvoiceNo = encodeURIComponent(cellValue);
            return "<a href=\"" + "#" + "\"" + " onclick=\"" + "popupform('" + InvoiceNo + "')" + "\"" + ">detail</a>";
        }

        function OpenForm(ctl) {

            var formUrl = '<%= ResolveUrl("~/forms/transaction/recInvoiceform.aspx") %>';

            var grid = $('#table');
            var jenisTagihan = [];
            var selIds = grid.jqGrid('getGridParam', 'selarrrow'),
                selText = [];
            $.each(selIds, function () {
                selText.push(grid.jqGrid('getCell', this, 'InvoiceNo'));

            });
            selTextPaymentNo = [];
            $.each(selIds, function () {
                selTextPaymentNo.push(grid.jqGrid('getCell', this, 'PaymentNo'));
            });


            if (ctl == 'print') {
                if (selIds.length == 0) {
                    alert('Pilih data yang mau di cetak !');
                }
                else if (selIds.length > 1) {
                    alert('Pilih satu record untuk cetak data.');
                }
                else {

                    var handlerUrl = '<%= ResolveUrl("~/AjaxHandler/Loaddata/gettransactiontype.ashx?method=getjenisinvoice") %>';
                    $.ajax({
                        type: 'POST',
                        url: handlerUrl + "&invoiceno=" + selText,
                        contentType: 'application/json',
                        dataType: 'json',
                        success: function (datas) {
                            $.each(datas, function (i, data) {
                                if (data.TransTypeName.toString().toLowerCase() == "registrasi") {
                                    window.open('../../forms/Transaction/recPrintInvoiceform.aspx?invoiceno=' + selText + "&action=registrasi", 'popUpWindow', 'height=400,width=800,left=300,top=200,resizable=yes,scrollbars=yes,toolbar=no,menubar=no,location=no,directories=no, status=yes');
                                }
                                else if (data.TransTypeName.toString().toLowerCase().contains("aksi korporasi")) {
                                    window.open('../../forms/Transaction/recPrintInvoiceform.aspx?invoiceno=' + selText + "&action=aksikorporasi", 'popUpWindow', 'height=400,width=800,left=300,top=200,resizable=yes,scrollbars=yes,toolbar=no,menubar=no,location=no,directories=no, status=yes');
                                }
                                else {
                                    window.open('../../reports/Transaction/rptInvoice.aspx?InvoiceNo=' + selText, 'popUpWindow', 'height=400,width=800,left=300,top=200,resizable=yes,scrollbars=yes,toolbar=no,menubar=no,location=no,directories=no, status=yes');
                                }

                            });

                        },
                        error: function () {
                            alert('Error load jenis invoice!');
                        }
                    });


                }
            }

            else {
                if (selIds.length == 0)
                    alert('Pilih data yang mau di hapus !');
                else if (selIds.length > 1) {
                    alert('Pilih satu record untuk hapus data.');
                }
                if (selTextPaymentNo != "")
                    alert('Data Tidak dapat dihapus, karena sudah ada pembayaran !');
                else {

                    var formInfoUrl = '<%= ResolveUrl("~/forms/transaction/recInvoiceInfoform.aspx") %>';

                    $('#dialog').load(formInfoUrl + '?id=' + selText + '&statusdata=delete&menuid=' + '<%= base.MenuID %>').dialog({ autoOpen: false, modal: true, width: 825, title: 'Hapus Tagihan' });
                    $("#dialog").dialog('open');

                }
            }

        }

        function getDebtor() {
            var handlerUrl = '<%= ResolveUrl("~/AjaxHandler/Loaddata/gettransactiontype.ashx?method=getjenisinvoice") %>';
            $.ajax({
                type: 'POST',
                url: handlerUrl + "&invoiceno=" + subsubsectors,
                contentType: 'application/json',
                dataType: 'json',
                success: function (datas) {
                    $.each(datas, function (i, data) {

                    });

                },
                error: function () {
                    alert('Error load jenis invoice!');
                }
            });

        }
    
    </script>
</asp:Content>
